﻿using Autofac.Extensions.DependencyInjection;
using NLog.Web;

namespace WebApiCoreFx
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateWebHostBuilder(string[] args)
        {
            string currentDirector = Directory.GetCurrentDirectory();

            IConfigurationRoot config = new ConfigurationBuilder()
                .SetBasePath(currentDirector)
                .AddJsonFile("appsettings.json", true)
                .Build();
            var ss = config.GetSection("Sentry").GetValue<string>("Dns");
            var sss = config["Sentry:Dns"];

            string[] urls = config.GetSection("StartUpUrls").Get<string[]>();
            //SentryOptions sentryOption = config.GetSection("Sentry").Get<SentryOptions>();
            IHostBuilder host = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new AutofacServiceProviderFactory()) //使用Autofac Ioc
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseKestrel()
                    .UseUrls(urls)
                    .UseContentRoot(currentDirector)
                    //.UseSentry((Sentry.AspNetCore.SentryAspNetCoreOptions options) =>
                    //{
                    //    options.Dsn = sentryOption.Dsn;
                    //    options.Environment = sentryOption.Environment;
                    //    options.MaxBreadcrumbs = sentryOption.MaxBreadcrumbs;
                    //    options.EnableTracing = sentryOption.EnableTracing;
                    //    options.MaxQueueItems = sentryOption.MaxQueueItems;
                    //    options.Debug = sentryOption.Debug;
                    //    options.ShutdownTimeout = TimeSpan.FromSeconds(5);
                    //    // Configures the root scope
                    //    options.ConfigureScope(s => s.SetTag("Always sent", "this tag"));
                    //})
                    .UseStartup<Startup>();
                }).UseNLog();



            return host;
        }

    }
}